/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Board extends JPanel implements Runnable,MouseListener {
    
    private Rect[] rect;
    private Thread thread;
    private int num;
    public boolean play;
    public BufferedImage img; 
    public void Board(){
            init();
            thread = new Thread(this);
            thread.start();
            this.num=3;
   }
    public void  init(){
        rect = new Rect[num];
        for(int i=0;i<num;i++){
        rect[i]= new Rect("Board"+i,1024/2,350-60*i,100,60,false,false);
        
        }
    }
   public void paint(Graphics g){
       
        g.drawImage(img,1024,700, this);
        for(int i=0;i<num;i++){
        g.fillRect(rect[i].getX(), rect[i].getY(),rect[i].getWeight(),rect[i].getWeight());
        }
   }
   public static BufferedImage loadImage(String ref) {  
        BufferedImage bimg = null;  
        try {  
            bimg = ImageIO.read(new File(ref));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return bimg;  
    }

    public void run() {
        img =this.loadImage("img9.png");
        while(true){
        repaint();
        }
        
    }
    
    public void mouseClicked(MouseEvent e) {
        for(int i=0;i<num;i++){
        
        if(rect[i].Contain(e.getX(),e.getY())){
            play=true;
            System.out.println("acc");
        }
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
        
    }

    public void mouseEntered(MouseEvent e) {
        
    }

    public void mouseExited(MouseEvent e) {
      
    }
  
}
